import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;



public class Form {
	
	private JFrame frame;
	private JTable table;
	private JPanel panel;
	int fields = 10;
	int rows = 20;
	int cols = 30;
	int rowheight = 20;
	int fieldheight = 40;
	int colwidth = 45;


	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Form window = new Form();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}


	public Form() {
		initialize();
	}


	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, cols * colwidth, (fields * fieldheight)
				+ (rows * rowheight));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new GridLayout(0, 1, 0, 0));

		JSplitPane splitPane = new JSplitPane();
		splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);

		GridBagConstraints gbc_splitPane = new GridBagConstraints();
		gbc_splitPane.fill = GridBagConstraints.BOTH;
		gbc_splitPane.gridx = 0;
		gbc_splitPane.gridy = 0;
		frame.getContentPane().add(splitPane);

		JScrollPane listPane = new JScrollPane();
		splitPane.setRightComponent(listPane);

		table = new JTable();
		table.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				System.out.println(arg0);
			}
		});

		
		table.setModel(createTableModel());
		listPane.setViewportView(table);
		panel = new JPanel();
		splitPane.setLeftComponent(panel);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] { 150, 300, 0, 0 };
		gbl_panel.rowHeights = new int[] { rowheight, 0, 0 };
		gbl_panel.columnWeights = new double[] { 0.0, 1.0, 0.0,
				Double.MIN_VALUE };
		gbl_panel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
		panel.setLayout(gbl_panel);
		for (int i = 0; i < fields; i++) {
			addField(RandomString.generateStringAlpha(10),
					RandomString.generateStringAlpha(10), i);

		}
	}

	DefaultTableModel createTableModel(){
		DefaultTableModel mtm = new DefaultTableModel();
		for (int j = 0; j < rows; j++) {
			Vector<String> ro = new Vector<String>();
			
			
			ro.add("aaaa");
			ro.add("bbb");
			ro.add("ccc");
			ro.add("aaaa");
			ro.add("bbb");
			ro.add("ccc");
			ro.add("aaaa");
			ro.add("bbb");
			ro.add("ccc");
			/*
			for (int i = 0; i < cols; i++) {
				ro.add(RandomString.generateStringAlpha(10));
			}*/
			mtm.addRow(ro);
		}
	//	Vector co = new Vector();
		for (int i = 0; i < cols; i++) {
			//co.add(RandomString.generateStringAlpha(5));
			mtm.addColumn(RandomString.generateStringAlpha(5));
		}
		mtm.addColumn(RandomString.generateStringAlpha(5));
		return mtm;
	}
	
	void addField(String label, String text, int y) {
		JLabel lba = new JLabel(label);
		GridBagConstraints gbc_lba = new GridBagConstraints();
		gbc_lba.anchor = GridBagConstraints.EAST;
		gbc_lba.insets = new Insets(0, 0, 5, 5);
		gbc_lba.gridx = 0;
		gbc_lba.gridy = y;
		panel.add(lba, gbc_lba);

		JTextField tfa = new JTextField();
		tfa.setText(text);
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.insets = new Insets(0, 0, 5, 5);
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.gridx = 1;
		gbc_textField.gridy = y;
		panel.add(tfa, gbc_textField);
		tfa.setColumns(10);
	}

}
